<template>
  <div>
    <TopFilter
      :list="topFilterList"
      :cols="4"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => this.columns = columns"
    >
    </FilterTable>
    <BaseDialog
      :visible.sync="visible"
      :title="dialogTitle"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <EmpPanel :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>

  </div>
</template>

<script>
import {
  searchOperateLog,
 } from '@/api/admin/logManage/operateLog';
import { dictionary } from '@/utils/dictMixin';
import { getDealerUser } from '@/api/customerRepair/customerComplaint/customerComplaintReception';

export default {
  name: 'EmployeeInfo',
  mixins: [dictionary],
  components: {

  },
  data() {
    this.conf = {show: '查看' };
    return {
      topFilterList: this.createTopFilters(),
      fetchParams: {},
      visible: false,
      dialogTitle: '',
      fetchApi: searchOperateLog,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
    };
  },
  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '操作日期',
          fieldName: 'operateDateFrom',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '日志内容',
          fieldName: 'operateConntent',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '操作编号',
          fieldName: 'beComplaintEmp',
          placeholder: '请输入...'
        },
        {
          type: 'SELECT',
          label: '操作类别',
          fieldName: 'operateType',
          placeholder: '请选择...',
          itemList: this.createDictList('1009')
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作日期',
          dataIndex: 'operate_date',
          width: 140,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '日志内容',
          dataIndex: 'operate_content',
          width: 360,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '操作类别',
          dataIndex: 'operate_type',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1009'),
          render: props => {
            return <span>{this.createDictText(props.row.operate_type, '1009')}</span>;
          }
        },
        {
          title: '操作编号',
          dataIndex: 'operator',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '操作姓名',
          dataIndex: 'created_by',
          width: 120,
          sorter: true,
          filter: true,
          filterType: 'input',
          editType: 'select',
          editable: false,
          editItems: []
        },
        {
          title: '备注',
          dataIndex: 'remark',
          width: 230,
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },

    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}操作日志`;
      this.visible = true;
    },
    //获取全部员工
    async getEmp() {
      const res = await getDealerUser();
      let empList = res.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns.find(item => item.dataIndex === 'created_by').editItems = empList; //操作姓名
    }

  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.getEmp();
  }
};
</script>

<style lang="less">
</style>


